
#include <BFont>
#include <BWidget>
#include "member_BDoubleSpinBox.h"

using namespace BWE;

member_BDoubleSpinBox::member_BDoubleSpinBox(BDoubleSpinBox* spinbox)
{
	boss = spinbox;
	value = 0;
	decimals = 3;
	range.set(-99999999.0, 99999999.0);
	step = 1;
	text = value;
	changed = false;
	pressed = false;
	align = Align_Left | Align_VCenter;
	hoverIndex = -1;
	inputIndex = -1;
	inputCount = 0;
	buttonShown = false;
}
member_BDoubleSpinBox::~member_BDoubleSpinBox()
{

}

bool member_BDoubleSpinBox::freshRects()
{
	const BFont* font = boss->font();
	if (!font)
		return false;

	rects.resize(text.size() + 1);

	BRect crect = boss->clientRect();
	BSize textSize = font->textSize(text);
	BSize prefixSize = font->textSize(prefix);
	BSize suffixSize = font->textSize(suffix);

	prefixRect.set(crect.left(), crect.top(), prefixSize.width(), prefixSize.height());

	crect.left() += prefixSize.width();
	crect.right() -= suffixSize.width();
	textRect = crect.align(align, textSize);
	if (textRect.left() < crect.left())
		textRect.setPos(crect.x(), textRect.y());

	suffixRect.set(textRect.right(), textRect.top(), suffixSize.width(), suffixSize.height());

	int tx = textRect.x();
	int ty = textRect.y();
	int ch = textSize.height();
	for (int i = 0; i < text.size(); i++)
	{
		char c = text[i];
		int cw = font->codeWidth(c);
		rects[i].set(tx, ty, cw, ch);
		tx += cw;
	}
	rects.last() = BRect(tx, ty, font->width(), ch);
	if (inputIndex < 0)
		inputIndex = 0;
	if (inputIndex > text.size())
		inputIndex = text.size();
	return true;
	if (inputIndex + inputCount >= text.size())
	{
		inputCount = text.size() - inputIndex;
	}
	return true;
}
